<template>
	<view class="item" @click="getDetails">
		<view class="bg-white Grid--flexCells item_content">
			<view class="Grid--flexCells Grid-cell Grid--center Grid--justifyCenter title">
				<view class="Grid-cell Grid--center title_left">
					<view class="name">{{item.competition && item.competition.name}}</view>
					<view class="time">{{item.match_time}}</view>
				</view>
				<view v-if="item.match_info" :class="['title_center', [0, 1, 9, 10, 11, 12, 13].includes(item.match_info.status_id) ? 'green' : 'red']">
					{{COMPETITION_STATUS[item.match_info.status_id]}}
				</view>
				<view class="title_right">查看详情</view>
			</view>
			<view class="Grid--flexCells Grid-cell Grid--center team">
				<view class="Grid--center team_left" v-if="item.home_team">
					<div style="position: absolute;left: 0;" id="star" @click.stop="handleCollect(item)" :class="{'fill': item.flag ? true : false}"></div>
					<text class="homeTeam">{{item.home_team.team_name}}</text>
					<image class="homeTeamLogo" :src="item.home_team.logo"></image>
				</view>
				<view v-if="item.match_info && [0, 1].includes(item.match_info.status_id)" class="team_center green">
					VS
				</view>
				<view v-if="item.match_info && ![0, 1].includes(item.match_info.status_id)" class="team_center red textWeight">
					{{item.match_info.home_bifen}}-{{item.match_info.away_bifen}}
				</view>
				<view class="Grid--center team_right" v-if="item.away_team">
					<image class="guestTeamLogo" :src="item.away_team.logo"></image>
					<text class="guestTeam">{{item.away_team.team_name}}</text>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		matchFocus
	} from '@/service/index.js'
	import {
		mapState
	} from "vuex";
	export default {
		name: 'Item',
		inject: ['callRefresh'],
		props: {
			item: {
				type: Object,
				default: () => []
			},
			// 当前swiper切换到第几个index
			currentIndex: {
				type: Number,
				default: function() {
					return 0
				}
			},
			clickIndex: {
				type: Number,
				default: ''
			},
		},
		data() {
			return {
				status: 1, //0未开始 1进行中 2已完赛
				isCollect: false,
				COMPETITION_STATUS: {
					0: '异常',
					1: '未开赛',
					2: '上半场',
					3: '中场',
					4: '下半场',
					5: '加时赛',
					6: '加时赛',
					7: '点球决战',
					8: '完场',
					9: '推迟',
					10: '中断',
					11: '腰斩',
					12: '取消',
					13:'待定',
				}
			}
		},
		computed: {
			...mapState({
				userInfo: state => state.login.userInfo,
				token: state => state.login.token,
			})
		},
		mounted() {},
		destroyed() {},
		onHide() {},
		methods: {
			async handleCollect(item) {
				if (this.token) {
					try {
						const {
							data
						} = await matchFocus({
							match_id: item.match_id,
							flag: !item.flag ? 1 : 0
						})
						console.log(data)
						// this.isCollect = !item.flag ? true : false
						this.callRefresh()
					} catch (e) {
						// TODO handle the exception
					}
				} else {
					uni.navigateTo({
						url: `/pages/login/login`
					})
				}
				
			},
			getDetails() {
				if (this.token) {
					uni.navigateTo({
						url: `/pages/details/details?match_id=${this.item.match_id}`
					})
				} else {
					uni.navigateTo({
						url: `/pages/login/login`
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import "@/assets/star/index.css";

	.item {
		position: relative;
		padding: 0px 16rpx;
		margin-bottom: 10rpx;

		.bg-white {
			border-radius: 10rpx;
		}

		.item_content {
			padding: 20rpx 30rpx;

			.title {
				position: relative;
				margin-bottom: 32rpx;

				.title_left {
					position: absolute;
					left: 0;

					.name {
						width: 164rpx;
						font-weight: 400;
						font-size: 24rpx;
						color: #5A54D4;
					}

					.time {
						font-weight: 400;
						font-size: 24rpx;
						color: #999999;
					}
				}

				.title_center {
					font-weight: bold;
					font-size: 24rpx;
					color: #0DA25F;
				}

				.title_right {
					position: absolute;
					right: 0;
					width: 118rpx;
					height: 40rpx;
					border-radius: 4rpx 4rpx 4rpx 4rpx;
					border: 2rpx solid #D3D3D3;
					font-size: 24rpx;
					color: #999999;
					display: flex;
					align-items: center;
					justify-content: center;
				}
			}

			.team {
				position: relative;

				.team_left {
					width: calc(50% - 48rpx);
					text-align: right;
					font-weight: bold;
					font-size: 24rpx;
					color: #000000;
					display: flex;
					.attention {
						width: 32rpx;
						height: 32rpx;
						position: absolute;
						left: 0;
					}

					.homeTeam {
						width: calc(100% - 104rpx);
						display: inline-block;
						// white-space: nowrap;
						// overflow: hidden;
						// text-overflow: ellipsis;
						overflow: auto;
						margin-left: 52rpx;
					}

					.homeTeamLogo {
						width: 32rpx;
						height: 32rpx;
						margin-left: 20rpx;
					}
				}

				.team_center {
					width: 96rpx;
					height: 38rpx;
					text-align: center;
					font-weight: 500;
					font-size: 32rpx;
					color: #0DA25F;
					line-height: 32rpx;
				}

				.team_right {
					width: calc(50% - 48rpx);
					text-align: left;
					font-weight: bold;
					font-size: 24rpx;
					color: #000000;
					display: flex;
					.guestTeamLogo {
						width: 32rpx;
						height: 32rpx;
						margin-right: 20rpx;
					}

					.guestTeam {
						width: calc(100% - 52rpx);
						display: inline-block;
						// white-space: nowrap;
						// overflow: hidden;
						// text-overflow: ellipsis;
						overflow: auto;
					}
				}
			}
		}

		.red {
			color: #E53F3E !important;
		}

		.textWeight {
			font-weight: bold !important;
		}

		.gray {
			color: #999999 !important;
		}

		.green {
			color: #0DA25F !important;
		}
	}
</style>